// Chat.module.scss
.chatContainer {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  border-radius: 20px;
  .chatHeader {
    user-select: none;
    border-radius: 20px 20px 0 0;
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e8e8e8;
    background-color: #a680b9;
    position: sticky;
    top: 0;
    z-index: 10;

    h2 {
      margin: 0 0 0 12px;
      font-size: 18px;
      font-weight: 500;
      color: #fff;
      flex: 1; // 让标题占据剩余空间
    }

    .backButton {
      margin-right: 12px;
      color: #fff;
      font-size: 28px;
    }

    .saveButton {
      font-size: 14px;
      margin-left: auto;
      color: #fff;
    }
  }

  .messagesContainer {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background-color: #f5f5f5;
    display: flex;
    flex-direction: column;

    .messageWrapper {
      margin-bottom: 16px;
      display: flex;
      flex-direction: column;

      &.userMessage {
        align-items: flex-end;

        .messageContent {
          flex-direction: row-reverse;
        }

        .messageBubble {
          background-color: #1890ff;
          color: #fff;
          border-radius: 16px 16px 0 16px;
        }
      }

      &.aiMessage {
        align-items: flex-start;
        .messageBubble {
          background-color: #fff;
          border-radius: 16px 16px 16px 0;
        }
      }

      .messageContent {
        display: flex;
        align-items: flex-end;
        max-width: 80%;
      }

      .messageAvatar {
        margin: 0 8px;
        flex-shrink: 0;
      }

      .messageBubble {
        padding: 12px 16px;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
        word-break: break-word;
      }

      .messageTime {
        font-size: 12px;
        color: #999;
        margin-top: 4px;
        padding: 0 8px;
      }
    }
  }

  .inputContainer {
    user-select: none;
    padding: 16px 0 0 0;
    background-color: #fff;
    border-top: 1px solid #e8e8e8;
    position: relative;
    z-index: 10;
    

    .inputWrapper {
      width: 98%; // 限制输入区域的最大宽度
      margin: 0 auto; // 水平居中
      display: flex;
      height: 100px;
      align-items: flex-end; // 让按钮与输入框底部对齐
      background-color: #fff;
      border-radius: 10px;
      padding: 8px 16px;
      box-shadow: 0 -2px 10px #a680b9;

      .input {
        flex: 1;
        border: none;
        background: transparent;
        padding: 12px 0;
        min-height: 48px; // 设置更高的默认高度
        resize: none;
        vertical-align: middle;
        &:focus {
          outline: none;
          box-shadow: none;
        }
      }

      .sendButton {
        height: 38px;
        width: 38px;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-left: 8px;
        margin-bottom: 5px; // 微调按钮位置
        &:enabled {
          background-color: #a680b9;
        }
      }
    }
  }

  .loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
  }

  .scrollButton {
    position: fixed;
    right: 20px;
    bottom: 100px;
    z-index: 9;
    opacity: 0.7;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);

    &:hover {
      opacity: 1;
    }
  }
}

// 添加媒体查询以适应移动设备
@media (max-width: 768px) {
  .chatContainer {
    .inputContainer {
      padding: 12px;

      .inputWrapper {
        padding: 6px 12px;

        .input {
          min-height: 40px;
        }

        .sendButton {
          height: 34px;
          width: 34px;
        }
      }
    }

    .scrollButton {
      right: 12px;
      bottom: 90px;
    }
  }
}
